import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import { registerApplication, start } from 'single-spa'

Vue.config.productionTip = false

async function loadScript (url) {
  return new Promise((resolve, reject) => {
    const script = document.createElement('script')
    script.src = url
    script.onload = resolve
    script.onerror = reject
    document.head.appendChild(script)
  })
}

registerApplication('singleSpaVue', async () => {
  console.log('加载模块')
  // systemJS
  await loadScript('http://localhost:8081/js/chunk-vendors.js')
  await loadScript('http://localhost:8081/js/app.js')
  return window.singleSpaVue
}, location => location.pathname.startsWith('/vue'))

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

start()
